-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Pervasive replacement of nkRecWhen in generic types #8748
Conversation
Hrm, OK, but we could also have changed the definition of |
b6b3a22
to
bd947e0
Compare
bd947e0
to
bb8dfe5
Compare
compiler/semtypinst.nim
Outdated
@@ -185,6 +218,11 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0): PNode = | |||
for i in countup(0, sonsLen(n) - 1): | |||
var it = n.sons[i] | |||
if it == nil: illFormedAst(n, cl.c.config) | |||
if mdbg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this debug code.
compiler/semtypinst.nim
Outdated
@@ -198,6 +236,9 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0): PNode = | |||
if branch == nil: branch = it.sons[0] | |||
else: illFormedAst(n, cl.c.config) | |||
if branch != nil: | |||
if mdbg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this debug code.
compiler/semtypinst.nim
Outdated
var branch: PNode = nil # the branch to take | ||
for i in countup(0, sonsLen(n) - 1): | ||
var it = n.sons[i] | ||
if mdbg: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this debug code.
Long story short, even if the type contains no reference at all to its generic parameters we still have to walk its AST and evaluate any nkRecWhen nodes that semRecordNodeAux skipped due to the type being a generic one. We also must be careful to modify the type `n` node in place since it may be referenced by the caller as seen in the tillegaltyperecursion test. Moreover we also can't have the nkSym drift away from their original values in order not to break the JS nkObjConstr codegen.
bb8dfe5
to
5afcd09
Compare
Long story short, even if the type contains no reference at all to its
generic parameters we still have to walk its AST and evaluate any
nkRecWhen nodes that semRecordNodeAux skipped due to the type being a
generic one.
We also must be careful to modify the type
n
node in place since itmay be referenced by the caller as seen in the tillegaltyperecursion
test.
I found this to be the nicest solution to the problem, we can't perform this resolution before the type is fully constructed as some
when
statements may refer to generic parameters and performing yet another (it'd be the third) pass over the type in order to resolve the remainingnkRecWhen
is not that nice performance-wise.This fixes #8417 and half of #7378.